package com.zhixiang.xaec.action.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.system.Template;
import com.zhixiang.xaec.service.system.TemplateService;
@Controller
@Scope("prototype")
public class TemplateAction extends BaseAction
{

    private static final long serialVersionUID = -5210324426491642564L;
    
    private Template template;
    
       
    public Template getTemplate()
    {
        return template;
    }

    public void setTemplate(Template template)
    {
        this.template = template;
    }

    @Autowired
    TemplateService  templateService;
    
    public String list(){
        QueryFilter localQueryFilter=new QueryFilter(getRequest());
        List<Template> localList=templateService.getAll(localQueryFilter);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        setResult(localList);
        return SUCCESS;
    }
    
    public String delete(){
        try
        {
            String[] ids=getRequest().getParameterValues("ids");
            templateService.delete(ids);       
            return SUCCESS;
        }
        catch (Exception e)
        {
            setSuccess(false);
            setMsg("模板正在使用不能被删除！");
            return SUCCESS;
        }
        
    }

    
    public String get(){
        String id=getRequest().getParameter("id");
        if(!"".equals(id)&&id!=null){
           setResult(templateService.get(Long.valueOf(id)));
        }        
        return SUCCESS;
    }
    
    public String save(){
        templateService.save(template);
        return SUCCESS;
    }
    
    public String checkUsed(){
        String id=getRequest().getParameter("id");
        String ttName=getRequest().getParameter("ttName");
        if(!"".equals(id)&&id!=null)
        setTotalCounts(templateService.checkUsed(id,ttName));
        return SUCCESS;
    }
}
